home *** CD-ROM | disk | FTP | other *** search
/ Clickx 115 / Clickx 115.iso / software / tools / windows / tails-i386-0.16.iso / live / filesystem.squashfs / var / lib / dpkg / info / sysv-rc.postinst < prev    next >
Encoding:
Text File  |  2012-03-26  |  6.2 KB  |  219 lines

  1. #!/bin/sh
  2.  
  3. set -e
  4.  
  5. . /usr/share/debconf/confmodule
  6. db_version 2.0
  7.  
  8. now=`date +%Y%m%dT%H%M`
  9. logdir=/var/lib/insserv
  10. logfile="$logdir/run-$now.log"
  11. flagfile=/etc/init.d/.legacy-bootordering
  12.  
  13. # Make sure insserv is in path
  14. PATH=/sbin:$PATH
  15.  
  16. # Based on code from dash postinst
  17. check_divert() {
  18.     package=insserv
  19.     div=$(dpkg-divert --list $2)
  20.     distrib=${4:-$2.distrib}
  21.     case "$1" in
  22.     false)
  23.         if [ -n "$div" ] && [ -z "${div%%*by $package}" ]; then
  24.         mv $distrib $2
  25.         dpkg-divert --package $package --remove $2
  26.     fi
  27.     ;;
  28.     status) # Return true if the divert is in effect
  29.         if [ -n "$div" ] && [ -z "${div%%*by $package}" ]; then
  30.             :
  31.     else
  32.         false
  33.     fi
  34.     esac
  35. }
  36.  
  37.  
  38. convert_rc_s_to_k() {
  39.   runlevel=$1
  40.   for link in $(cd $target/etc/rc$runlevel.d; ls S* || true); do
  41.       set `echo $link|sed "s%S\(..\)\(.*\)%\1 \2%"`
  42.       seq=$1
  43.       service=$2
  44.       mv $target/etc/rc$runlevel.d/$link $target/etc/rc$runlevel.d/K$seq$service
  45.   done
  46. }
  47.  
  48. add_problematic() {
  49.     msg="$1"
  50.     if [ -z "$PROBLEMATIC" ] ; then
  51.     PROBLEMATIC="$msg"
  52.     else
  53.     PROBLEMATIC="$PROBLEMATIC, $msg"
  54.     fi
  55. }
  56.  
  57. is_unsafe_to_activate() {
  58.     retval=1
  59.     # Refuse to convert when there are obsolete init.d scripts left
  60.     # behind, as these tend to confuse the boot sequence.
  61.     echo "info: Checking if it is safe to convert to dependency based boot." 1>&2
  62.     for package in $(dpkg -S $(find /etc/init.d -type f -perm /+x) \
  63.                      2>/dev/null | cut -d: -f1 | sort -u); do
  64.         obsolete_initscripts=$(dpkg-query -W -f='${Conffiles}\n' $package | \
  65.         grep 'obsolete$' | grep -o '/etc/init.d/[^ ]\+') || :
  66.         if [ "$obsolete_initscripts" ]; then
  67.             for initscript in $obsolete_initscripts; do
  68.                 if [ -e "$initscript" ]; then
  69.                     retval=0
  70.                     add_problematic "package $package left obsolete init.d script behind"
  71.                 fi
  72.             done
  73.         fi
  74.     done
  75.  
  76.     # Refuse to migrate if insserv find problems, like loops,
  77.     # duplicate provides, script providing system facility or missing
  78.     # header completely.
  79.     insserv -nv > $logfile 2>&1 || true
  80.     errstr='There is a loop between|loop involving service|already provided!|provides system facility|missing LSB tags'
  81.     if egrep -q "$errstr" $logfile ; then
  82.     msg=$(egrep "$errstr" $logfile | sed 's/$/, /' | tr "\n" " ")
  83.     retval=0
  84.     add_problematic "$msg"
  85.  
  86.     # If insserv found problems, report removed but not purged
  87.     # packages, as their dependency information is probably
  88.     # outdated or missing, leading to incorrect ordering.
  89.     for package in $(dpkg -l $(dpkg -S /etc/init.d/* 2>/dev/null |
  90.         cut -d: -f1 |sort -u)|grep ^rc|awk '{print $2}') ; do
  91.         retval=0
  92.         add_problematic "package $package removed but not purged"
  93.     done
  94.     fi
  95.     rm $logfile
  96.     return $retval
  97. }
  98.  
  99. activate_insserv() {
  100.     # Save the current sequence numbers in
  101.     # /var/lib/update-rc.d/.  This directory will be updated
  102.     # when update-rc.d is called, to make it possible to migrate away
  103.     # from dependency based boot sequencing.  If some script is
  104.     # missing in /var/lib/update-rc.d/, one will have to
  105.     # reconfigure the package it belong to for update-rc.d to update
  106.     # the content in /var/lib/update-rc.d/.
  107.     /usr/share/sysv-rc/saveconfig -s /var/lib/update-rc.d
  108.  
  109.     echo "info: Reordering boot system, log to $logfile" 1>&2
  110.     (
  111.     echo "info: Converting rc0.d/S* and rc6.d/S* to K*." 1>&2
  112.     convert_rc_s_to_k 0
  113.     convert_rc_s_to_k 6
  114.     echo "info: running insserv" 1>&2
  115.     insserv -v
  116.     ) > $logfile 2>&1
  117.  
  118.     # Indicate that system is no longer using the legacy ordering
  119.     rm $flagfile
  120.  
  121.     return 0
  122. }
  123.  
  124. try_to_convert() {
  125.     PROBLEMATIC=""
  126.     if is_unsafe_to_activate ; then
  127.     # Make sure the note is seen every time
  128.     db_fset sysv-rc/unable-to-convert seen false
  129.     db_subst sysv-rc/unable-to-convert PROBLEMATIC "$PROBLEMATIC"
  130.     db_input critical sysv-rc/unable-to-convert || [ $? -eq 30 ]
  131.     db_go || true
  132.     return 1
  133.     else
  134.     # Ask if the legacy boot sequence should be converted to
  135.     # dependency based.
  136.  
  137.     # Priority is critical during upgrades, to give those with
  138.     # existing installations a good  chance of seeing and rejecting
  139.     # the migration.
  140.     db_input critical sysv-rc/convert-legacy || [ $? -eq 30 ]
  141.  
  142.     db_go
  143.     db_get sysv-rc/convert-legacy || true
  144.     if [ true = "$RET" ] ; then
  145.         if activate_insserv ; then
  146.         echo "success: Enabled dependency based boot system." 1>&2
  147.         else
  148.         echo "error: Something failed while migrating." 1>&2
  149.         fi
  150.     else
  151.         echo "warning: Asked to not convert legacy boot sequence to dependency based boot sequencing." 1>&2
  152.     fi
  153.     fi
  154. }
  155.  
  156. case "$1" in
  157.     configure)
  158.         # Remove divert created by insserv during upgrades if it
  159.         # exist.  It was dropped in insserv 1.12.0-11 converted since
  160.         # sysvinit 2.87dsf-3, 2009-08-19.
  161.         if [ -f /var/run/sysv-rc.upgrade ]; then
  162.         lastver=$(cat /var/run/sysv-rc.upgrade)
  163.         if dpkg --compare-versions "$2" lt 2.87dsf-3 ; then
  164.         if check_divert status /usr/sbin/update-rc.d \
  165.             /usr/sbin/update-rc.d-insserv ; then
  166.             check_divert false /usr/sbin/update-rc.d \
  167.             /usr/sbin/update-rc.d-insserv
  168.             rm /var/lib/insserv/using-insserv
  169.         else
  170.             touch $flagfile
  171.         fi
  172.         fi
  173.         rm /var/run/sysv-rc.upgrade
  174.     fi
  175.  
  176.     # Detect migrations away from file-rc, where the legacy boot
  177.     # ordering is used but the flag file to indicated legacy boot
  178.     # ordering is missing.  Can not do this in preinst, as preinst
  179.     # might be executed before the postinst of file-rc creatingthe
  180.     # files in /etc/rc?.d/.
  181.     for f in /etc/rc0.d/S* ; do
  182.         if [ ! -f $flagfile ] && [ -f $f ] ; then
  183.         touch $flagfile
  184.         break
  185.         fi
  186.     done
  187.  
  188.     if [ -f $flagfile ] ; then
  189.         # Still using legacy ordering, try to convert
  190.         if try_to_convert ; then
  191.         :
  192.         else
  193.         cat 1>&2 <<EOF
  194.  
  195. error: Unable to migrate to dependency based boot sequencing.
  196. error: Problems detected: $PROBLEMATIC
  197.  
  198. See http://wiki.debian.org/LSBInitScripts/DependencyBasedBoot for
  199. more information about dependency based boot sequencing. To
  200. reattempt the migration process run 'dpkg-reconfigure sysv-rc'.
  201.  
  202. EOF
  203.         fi
  204.     fi
  205.     if dpkg --compare-versions "$2" lt 2.87dsf-5 ; then
  206.         removedfiles=$(grep -l 'remove$' /var/lib/update-rc.d/* 2>/dev/null || true)
  207.         if [ "$removedfiles" ] ; then
  208.         rm $removedfiles
  209.         fi
  210.     fi
  211.     ;;
  212.     *)
  213.     ;;
  214. esac
  215.  
  216. db_stop
  217.  
  218.  
  219.